<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('设置评分标准列表')" />
    <!-- 引入Layui样式（日期选择器依赖） -->
    <link th:href="@{/plugins/layui/css/layui.css}" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <!-- 原有搜索区域 -->
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>评分标准名称：</label>
                            <input type="text" name="standardName"/>
                        </li>
                        <li>
                            <label>指定课程：</label>
                            <select name="arrangementId" class="form-control" id="arrangementIdSelect">
                                <option value="">全部</option>
                                <option th:each="courseArrangement:${courseArrangements}" th:value="${courseArrangement.arrangementId}" th:text="${courseArrangement.courseName}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <!-- 原有操作按钮（修复权限绑定和初始状态） -->
        <div class="btn-group-sm" id="toolbar" role="group">
            <!-- 添加按钮：有权限则直接可用，无需选中状态 -->
            <a class="btn btn-success"
               onclick="$.operate.add()"
               shiro:hasPermission="college:scoreStandard:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <!-- 修改按钮：初始禁用，选中单行后启用 -->
            <a class="btn btn-primary single disabled"
               onclick="$.operate.edit()"
               shiro:hasPermission="college:scoreStandard:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <!-- 删除按钮：初始禁用，选中至少一行后启用 -->
            <a class="btn btn-danger multiple disabled"
               onclick="$.operate.removeAll()"
               shiro:hasPermission="college:scoreStandard:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <!-- 导出按钮：有权限则可用 -->
            <a class="btn btn-warning"
               onclick="$.table.exportExcel()"
               shiro:hasPermission="college:scoreStandard:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>

        <!-- 原有评分标准表格 -->
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>

<!-- 1. 实验项目列表模态框 -->
<div class="modal fade" id="experimentProjectListModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-xl" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">实验项目列表</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <!-- 实验项目搜索区域 -->
                <div class="search-collapse mb-3">
                    <form id="experimentProjectSearchForm">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label>实验项目名称：</label>
                                    <input type="text" name="projectName" placeholder="请输入项目名称"/>
                                </li>
                                <li>
                                    <label>所属学期：</label>
                                    <input type="text" name="semester" placeholder="例如：2024-2025-1"/>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-sm" onclick="experimentProjectTable.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-sm" onclick="$('#experimentProjectSearchForm')[0].reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>
                <!-- 实验项目表格 -->
                <div class="select-table table-striped">
                    <table id="experimentProjectTable"></table>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 2. 新增/编辑实验项目模态框 -->
<div class="modal fade" id="experimentProjectFormModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="formModalTitle">添加实验项目</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form id="experimentProjectForm" class="form-horizontal">
                <input type="hidden" name="projectId" id="projectId">
                <input type="hidden" name="arrangementId" id="formArrangementId">
                <input type="hidden" name="courseId" id="courseId">
                <input type="hidden" name="attachment" id="attachment">
                <div class="modal-body">
                    <!-- 课程名称（只读） -->
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label required">课程名称</label>
                        <div class="col-sm-10">
                            <input type="text" name="courseName" id="courseName" class="form-control" readonly>
                        </div>
                    </div>
                    <!-- 所属学期 -->
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label required">所属学期</label>
                        <div class="col-sm-10">
                            <input type="text" name="semester" class="form-control" placeholder="例如：2024-2025-1" required>
                        </div>
                    </div>
                    <!-- 实验项目名称 -->
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label required">实验项目名称</label>
                        <div class="col-sm-10">
                            <input type="text" name="projectName" class="form-control" placeholder="请输入实验项目名称" required>
                        </div>
                    </div>
                    <!-- 实验学时 -->
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label required">实验学时</label>
                        <div class="col-sm-10">
                            <select name="experimentPeriod" class="form-control" required>
                                <option value="">请选择</option>
                                <option value="2">2学时</option>
                                <option value="4">4学时</option>
                                <option value="6">6学时</option>
                                <option value="8">8学时</option>
                            </select>
                        </div>
                    </div>
                    <!-- 实验序号 -->
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label required">实验序号</label>
                        <div class="col-sm-10">
                            <input type="text" name="experimentNumber" class="form-control" placeholder="例如：1、2、3" required>
                        </div>
                    </div>
                    <!-- 实验时间 -->
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label required">实验时间</label>
                        <div class="col-sm-10">
                            <input type="text" name="experimentTime" id="experimentTime" class="form-control" placeholder="请选择实验时间" required>
                        </div>
                    </div>
                    <!-- 截止日期 -->
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label required">截止日期</label>
                        <div class="col-sm-10">
                            <input type="text" name="deadline" id="deadline" class="form-control" placeholder="请选择报告提交截止时间" required>
                        </div>
                    </div>
                    <!-- 实验目的 -->
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">实验目的</label>
                        <div class="col-sm-10">
                            <textarea name="purpose" class="form-control" rows="3" placeholder="请输入实验目的"></textarea>
                        </div>
                    </div>
                    <!-- 实验内容（富文本） -->
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">实验内容</label>
                        <div class="col-sm-10">
                            <div id="contentEditor" style="height: 200px;"></div>
                            <input type="hidden" name="content" id="content">
                        </div>
                    </div>
                    <!-- 附件上传 -->
                    <div class="form-group row">
                        <label class="col-sm-2 col-form-label">相关资料上传</label>
                        <div class="col-sm-10">
                            <input type="file" id="attachmentFile" class="form-control-file">
                            <div id="fileTip" class="text-muted mt-1">支持PDF、Word、PPT格式，最大50MB</div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- 底部JS区域 -->
<th:block th:include="include :: footer" />
<!-- laydate日期选择器 -->
<script th:src="@{/plugins/layui/layui.js}"></script>
<!-- wangEditor富文本编辑器 -->
<script th:src="@{/plugins/wangEditor/js/wangEditor.min.js}"></script>
<script th:inline="javascript">
    // 1. 修复：区分【评分标准】和【实验项目】的权限变量（避免混用导致按钮禁用）
    // 评分标准权限变量（控制顶部工具栏和表格评分标准操作）
    var scoreStandardAddFlag = [[${@permission.hasPermi('college:scoreStandard:add')}]];
    var scoreStandardEditFlag = [[${@permission.hasPermi('college:scoreStandard:edit')}]];
    var scoreStandardRemoveFlag = [[${@permission.hasPermi('college:scoreStandard:remove')}]];
    var scoreStandardExportFlag = [[${@permission.hasPermi('college:scoreStandard:export')}]];
    // 实验项目权限变量（仅控制实验项目相关操作）
    var expProEditFlag = [[${@permission.hasPermi('college:experimentProject:edit')}]];
    var expProRemoveFlag = [[${@permission.hasPermi('college:experimentProject:remove')}]];
    var expProAddFlag = [[${@permission.hasPermi('college:experimentProject:add')}]];

    var prefix = ctx + "college/scoreStandard";
    var expProPrefix = ctx + "college/experimentProject";
    var contentEditor = null;
    var experimentProjectTable = null;
    var laydateInstances = {};
    var scoreStandardTable = null;

    $(function() {
        // 初始化评分标准表格（含选中事件监听）
        initScoreStandardTable();
        // 初始化实验项目表格
        initExperimentProjectTable();
        // 初始化实验项目表单验证
        initExperimentProjectFormValidate();

        // 附件上传事件（保持不变）
        $('#attachmentFile').change(function() {
            var file = this.files[0];
            if (!file) return;
            var allowedTypes = ['application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
                'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'];
            if (!allowedTypes.includes(file.type)) {
                $('#fileTip').text('文件类型不支持，请上传PDF、Word或PPT格式').removeClass('text-info text-success').addClass('text-danger');
                return;
            }
            if (file.size > 50 * 1024 * 1024) {
                $('#fileTip').text('文件大小超过50MB限制').removeClass('text-info text-success').addClass('text-danger');
                return;
            }
            var formData = new FormData();
            formData.append('file', file);
            $.ajax({
                url: expProPrefix + "/upload",
                type: "POST",
                data: formData,
                processData: false,
                contentType: false,
                beforeSend: function() {
                    $('#fileTip').text('文件上传中...').removeClass('text-success text-danger').addClass('text-info');
                },
                success: function(result) {
                    if (result.code === 200) {
                        $('#attachment').val(result.data);
                        $('#fileTip').text('上传成功：' + file.name).removeClass('text-info text-danger').addClass('text-success');
                    } else {
                        $('#fileTip').text('上传失败：' + result.msg).removeClass('text-info text-success').addClass('text-danger');
                    }
                },
                error: function() {
                    $('#fileTip').text('上传异常，请重试').removeClass('text-info text-success').addClass('text-danger');
                }
            });
        });

        // 实验项目表单提交事件（保持不变）
        $('#experimentProjectForm').submit(function(e) {
            e.preventDefault();
            if (!$(this).valid()) {
                return;
            }
            if (contentEditor) {
                $('#content').val(contentEditor.txt.html());
            }
            var url = $(this).find('#projectId').val() ? expProPrefix + "/edit" : expProPrefix + "/add";
            var method = $(this).find('#projectId').val() ? "PUT" : "POST";
            $.ajax({
                url: url,
                type: method,
                contentType: "application/json",
                data: JSON.stringify($(this).serializeObject()),
                success: function(result) {
                    if (result.code === 200) {
                        toastr.success("操作成功！");
                        $('#experimentProjectFormModal').modal('hide');
                        experimentProjectTable.refresh();
                    } else {
                        toastr.error(result.msg);
                    }
                },
                error: function() {
                    toastr.error("请求异常，请重试！");
                }
            });
        });

        // 实验项目模态框事件（保持不变）
        $('#experimentProjectFormModal').on('shown.bs.modal', function() {
            initLaydate();
            initWangEditor();
        }).on('hidden.bs.modal', function() {
            destroyLaydateInstances();
            destroyWangEditor();
        });
    });

    /**
     * 2. 修复：评分标准表格初始化（添加选中事件监听，控制按钮启用/禁用）
     */
    function initScoreStandardTable() {
        if (scoreStandardTable) {
            return scoreStandardTable;
        }

        var scoreStandardOptions = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "评分标准",
            // 关键：添加表格选中事件，动态控制顶部按钮状态
            onCheck: function(row) {
                updateToolbarBtnStatus();
            },
            onUncheck: function(row) {
                updateToolbarBtnStatus();
            },
            onCheckAll: function(rows) {
                updateToolbarBtnStatus();
            },
            onUncheckAll: function(rows) {
                updateToolbarBtnStatus();
            },
            columns: [{
                checkbox: true
            },
                {
                    field: 'standardId',
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'standardName',
                    title: '评分标准名称'
                },
                {
                    field: 'arrangementId',
                    title: '指定课程ID',
                    visible: false
                },
                {
                    field: 'courseId',
                    title: '课程ID',
                    visible: false
                },
                {
                    field: 'courseName',
                    title: '课程名称'
                },
                {
                    field: 'totalScore',
                    title: '总分值'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        // 修复：表格评分标准操作按钮用【评分标准权限变量】，而非实验项目变量
                        actions.push('<a class="btn btn-danger btn-xs ' + (scoreStandardRemoveFlag ? '' : 'disabled') + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.standardId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + (scoreStandardEditFlag ? '' : 'disabled') + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.standardId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        // 实验项目操作按钮仍用实验项目权限变量（正确）
                        actions.push('<a class="btn btn-primary btn-xs ' + (expProEditFlag ? '' : 'disabled') + '" href="javascript:void(0)" onclick="openExperimentProjectList(' + row.arrangementId + ', \'' + row.courseName + '\', \'' + row.courseId + '\')"><i class="fa fa-list"></i>项目列表</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + (expProAddFlag ? '' : 'disabled') + '" href="javascript:void(0)" onclick="openAddExperimentProject(' + row.arrangementId + ', \'' + row.courseName + '\', \'' + row.courseId + '\')"><i class="fa fa-plus"></i>添加项目</a>');
                        return actions.join('');
                    }
                }]
        };

        // 清除缓存配置（避免重复初始化）
        if ($.table && $.table.destroy) {
            $.table.destroy('bootstrap-table');
        }

        scoreStandardTable = $.table.init(scoreStandardOptions);
        $('#bootstrap-table').data('bootstrap.table', scoreStandardTable);
        return scoreStandardTable;
    }

    /**
     * 3. 新增：更新顶部工具栏按钮状态的工具函数
     */
    function updateToolbarBtnStatus() {
        var selectedRows = $('#bootstrap-table').bootstrapTable('getSelections');
        var selectedCount = selectedRows.length;

        // 控制【修改】按钮：有权限 + 选中1行 → 启用
        var editBtn = $('.btn-primary.single');
        if (scoreStandardEditFlag && selectedCount === 1) {
            editBtn.removeClass('disabled');
        } else {
            editBtn.addClass('disabled');
        }

        // 控制【删除】按钮：有权限 + 选中≥1行 → 启用
        var removeBtn = $('.btn-danger.multiple');
        if (scoreStandardRemoveFlag && selectedCount >= 1) {
            removeBtn.removeClass('disabled');
        } else {
            removeBtn.addClass('disabled');
        }
    }

    /**
     * 实验项目表格初始化（保持不变）
     */
    function initExperimentProjectTable() {
        if (experimentProjectTable) {
            return experimentProjectTable;
        }
        var $table = $('#experimentProjectTable');
        experimentProjectTable = $.table.init({
            tableId: "experimentProjectTable",
            url: expProPrefix + "/list",
            modalName: "实验项目",
            columns: [{
                checkbox: true
            },
                {
                    field: 'projectId',
                    title: '项目ID',
                    visible: false
                },
                {
                    field: 'projectName',
                    title: '实验项目名称'
                },
                {
                    field: 'experimentPeriod',
                    title: '实验学时',
                    formatter: function(value) {
                        return value + "学时";
                    }
                },
                {
                    field: 'experimentNumber',
                    title: '实验序号'
                },
                {
                    field: 'experimentTime',
                    title: '实验时间',
                    formatter: function(value) {
                        return value ? formatDate(value, "yyyy-MM-dd HH:mm") : "-";
                    }
                },
                {
                    field: 'deadline',
                    title: '截止日期',
                    formatter: function(value) {
                        return value ? formatDate(value, "yyyy-MM-dd HH:mm") : "-";
                    }
                },
                {
                    field: 'semester',
                    title: '所属学期'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + (expProEditFlag ? '' : 'disabled') + '" href="javascript:void(0)" onclick="openEditExperimentProject(' + row.projectId + ')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + (expProRemoveFlag ? '' : 'disabled') + '" href="javascript:void(0)" onclick="deleteExperimentProject(' + row.projectId + ')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        });
        $table.data('bootstrap.table', experimentProjectTable);
        return experimentProjectTable;
    }

    /**
     * 日期选择器初始化（保持不变）
     */
    function initLaydate() {
        destroyLaydateInstances();
        layui.use('laydate', function() {
            var laydate = layui.laydate;
            laydateInstances.experimentTime = laydate.render({
                elem: '#experimentTime',
                type: 'datetime',
                theme: 'molv',
                trigger: 'click',
                format: 'yyyy-MM-dd HH:mm',
                done: function(value) {
                    $('#experimentTime').val(value);
                }
            });
            laydateInstances.deadline = laydate.render({
                elem: '#deadline',
                type: 'datetime',
                theme: 'molv',
                trigger: 'click',
                format: 'yyyy-MM-dd HH:mm'
            });
        });
    }

    function destroyLaydateInstances() {
        for (var key in laydateInstances) {
            if (laydateInstances[key] && typeof laydateInstances[key].close === 'function') {
                laydateInstances[key].close();
            }
        }
        laydateInstances = {};
    }

    /**
     * 富文本编辑器（保持不变）
     */
    function initWangEditor() {
        destroyWangEditor();
        contentEditor = new wangEditor('#contentEditor');
        contentEditor.config.uploadImgServer = expProPrefix + "/upload";
        contentEditor.config.uploadImgName = "file";
        contentEditor.config.uploadImgMaxSize = 5 * 1024 * 1024;
        contentEditor.config.uploadImgMaxLength = 1;
        contentEditor.config.uploadImgHooks = {
            fail: function(xhr, editor, resData) {
                toastr.error('图片上传失败: ' + (resData && resData.msg ? resData.msg : '未知错误'));
            },
            error: function(xhr, editor) {
                toastr.error('图片上传出错，请重试');
            },
            timeout: function(editor) {
                toastr.error('图片上传超时');
            }
        };
        contentEditor.config.menus = [
            'bold', 'italic', 'underline', 'strikeThrough', 'fontSize', 'fontName',
            'head', 'link', 'list', 'justify', 'quote', 'image', 'table'
        ];
        contentEditor.create();
    }

    function destroyWangEditor() {
        if (contentEditor && typeof contentEditor.destroy === 'function') {
            contentEditor.destroy();
            contentEditor = null;
        }
    }

    /**
     * 表单验证（保持不变）
     */
    function initExperimentProjectFormValidate() {
        $('#experimentProjectForm').validate({
            rules: {
                semester: { required: true, maxlength: 20 },
                projectName: { required: true, maxlength: 100 },
                experimentPeriod: { required: true },
                experimentNumber: { required: true, maxlength: 10 },
                experimentTime: { required: true },
                deadline: { required: true }
            },
            messages: {
                semester: { required: "请输入所属学期", maxlength: "学期长度不能超过20个字符" },
                projectName: { required: "请输入实验项目名称", maxlength: "项目名称不能超过100个字符" },
                experimentPeriod: { required: "请选择实验学时" },
                experimentNumber: { required: "请输入实验序号", maxlength: "序号长度不能超过10个字符" },
                experimentTime: { required: "请选择实验时间" },
                deadline: { required: "请选择截止日期" }
            },
            errorElement: "span",
            errorClass: "text-danger",
            errorPlacement: function(error, element) {
                element.after(error);
            }
        });
    }

    /**
     * 实验项目相关函数（保持不变）
     */
    function openExperimentProjectList(arrangementId, courseName, courseId) {
        $('#formArrangementId').val(arrangementId);
        $('#courseName').val(courseName);
        $('#courseId').val(courseId);
        experimentProjectTable.setQueryParams({arrangementId: arrangementId});
        $('#experimentProjectListModal').modal('show');
        experimentProjectTable.refresh();
    }

    function openAddExperimentProject(arrangementId, courseName, courseId) {
        $('#experimentProjectForm')[0].reset();
        $('#attachment').val('');
        $('#fileTip').text('支持PDF、Word、PPT格式，最大50MB').removeClass('text-success text-danger').addClass('text-muted');
        $('#formArrangementId').val(arrangementId);
        $('#courseName').val(courseName);
        $('#courseId').val(courseId);
        $('#projectId').val('');
        $('#formModalTitle').text('添加实验项目');
        $('#experimentProjectFormModal').modal('show');
    }

    function openEditExperimentProject(projectId) {
        $.ajax({
            url: expProPrefix + "/edit/" + projectId,
            type: "GET",
            success: function(result) {
                if (result.code === 200) {
                    var data = result.data;
                    $('#projectId').val(data.projectId);
                    $('#formArrangementId').val(data.arrangementId);
                    $('#courseId').val(data.courseId);
                    $('#courseName').val(data.courseName);
                    $('#semester').val(data.semester);
                    $('#projectName').val(data.projectName);
                    $('#experimentPeriod').val(data.experimentPeriod);
                    $('#experimentNumber').val(data.experimentNumber);
                    $('#experimentTime').val(formatDate(data.experimentTime, "yyyy-MM-dd HH:mm"));
                    $('#deadline').val(formatDate(data.deadline, "yyyy-MM-dd HH:mm"));
                    $('#purpose').val(data.purpose);
                    $('#attachment').val(data.attachment);
                    $('#formModalTitle').text('编辑实验项目');
                    $('#experimentProjectFormModal').one('shown.bs.modal', function() {
                        if (contentEditor) {
                            contentEditor.txt.html(data.content || '');
                        }
                    });
                    $('#experimentProjectFormModal').modal('show');
                    if (data.attachment) {
                        $('#fileTip').text('已上传：' + data.attachment.substring(data.attachment.lastIndexOf('/') + 1)).removeClass('text-info text-danger').addClass('text-success');
                    } else {
                        $('#fileTip').text('支持PDF、Word、PPT格式，最大50MB').removeClass('text-success text-danger').addClass('text-muted');
                    }
                } else {
                    toastr.error(result.msg);
                }
            },
            error: function() {
                toastr.error("获取数据失败，请重试！");
            }
        });
    }

    function deleteExperimentProject(projectId) {
        if (confirm("确定要删除该实验项目吗？删除后不可恢复！")) {
            $.ajax({
                url: expProPrefix + "/remove/" + projectId,
                type: "DELETE",
                success: function(result) {
                    if (result.code === 200) {
                        toastr.success("删除成功！");
                        experimentProjectTable.refresh();
                    } else {
                        toastr.error(result.msg);
                    }
                },
                error: function() {
                    toastr.error("删除失败，请重试！");
                }
            });
        }
    }

    /**
     * 日期格式化（保持不变）
     */
    function formatDate(dateStr, format) {
        if (!dateStr) return '';
        var date;
        if (typeof dateStr === 'string') {
            dateStr = dateStr.replace(/-/g, '/');
            date = new Date(dateStr);
        } else if (dateStr instanceof Date) {
            date = dateStr;
        } else {
            return '';
        }
        if (isNaN(date.getTime())) {
            return '';
        }
        var o = {
            "M+": date.getMonth() + 1,
            "d+": date.getDate(),
            "H+": date.getHours(),
            "m+": date.getMinutes(),
            "s+": date.getSeconds()
        };
        if (/(y+)/.test(format)) {
            format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            }
        }
        return format;
    }
</script>
</body>
</html>